package com.example.administrator.yunniuusedcar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.model.mode_benn.RanCarXiangQingBean;
import com.example.administrator.yunniuusedcar.util.ListViewUtil;
import com.example.administrator.yunniuusedcar.view.NoScrollListView;

import java.util.List;

/**
 * Created by Administrator on 2018/1/4 0004.
 */

public class GuiGeAdapter extends BaseAdapter {
    Context context;
    GuiGeAttrAdapter attrAdapter;
    public GuiGeAdapter(Context context) {
        this.context = context;

    }

    @Override
    public int getCount() {
        if(spec==null)
            return 0;
        return spec.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.fragment_guige_item,null);
        attrAdapter = new GuiGeAttrAdapter(context);
        TextView type_name = (TextView)v.findViewById(R.id.type_name);
        type_name.setText(spec.get(i).spec_type);

        NoScrollListView attr_listview = (NoScrollListView)v.findViewById(R.id.attr_listview);

        attr_listview.setAdapter(attrAdapter);
        attrAdapter.setData(spec.get(i).spec_value);

        ListViewUtil.setListViewHeightBasedOnChildren(attr_listview);
        return v;
    }

    List<RanCarXiangQingBean.Data.Spec> spec ;
    public void setData(List<RanCarXiangQingBean.Data.Spec> spec) {
        this.spec = spec;
        notifyDataSetChanged();
    }
}
